package com.sanjishu.enterlab.electricity.sale.service;

import com.sanjishu.enterlab.electricity.sale.domain.UserSetting;
import com.sanjishu.enterlab.electricity.sale.mapper.UserSettingMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class UserSettingService {

    @Autowired
    private UserSettingMapper userSettingMapper;

    public UserSetting findByUserId(Integer userId) {
        return userSettingMapper.findByUserId(userId);
    }

    public void createUserSetting(Integer userId, Integer num1, Integer num2, Integer num3) {
        UserSetting userSetting = new UserSetting();
        userSetting.setUserId(userId);
        userSetting.setNum1(num1);
        userSetting.setNum2(num2);
        userSetting.setNum3(num3);
        userSetting.setCreatedAt(new Date());
        userSettingMapper.insert(userSetting);
    }

    public void updateUserSetting(Integer userId, Integer num1, Integer num2, Integer num3) {
        UserSetting userSetting = findByUserId(userId);
        if (userSetting != null) {
            if (num1 != null) {
                userSetting.setNum1(num1);
            }
            if (num2 != null) {
                userSetting.setNum2(num2);
            }
            if (num3 != null) {
                userSetting.setNum3(num3);
            }
            userSettingMapper.updateByPrimaryKey(userSetting);
        }
    }
}
